package com.kwz.common.ui.components.initializers;

import java.awt.Component;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import com.kwz.common.CommonException;
import com.kwz.common.Context;
import com.kwz.common.IContext;
import com.kwz.common.designpatterns.ExceptionManager;
import com.kwz.common.designpatterns.factory.BadContextException;
import com.kwz.common.ui.components.IUiComponentContextInitializer;
import com.kwz.common.ui.components.IUiComponentInitializer;

/**
 * <p>
 * 		Initialiseur par defaut pour JComboBox
 * </p> 
 *
 * @author mbi
 */
public class UiDefaultJComboBoxInitializer extends UiDefaultComponentInitializer implements IUiComponentInitializer, IrUiInitializers {

    /**
     * 
     */
    public UiDefaultJComboBoxInitializer() {
        super();

    }

    /* (non-Javadoc)
     * @see com.kwz.common.ui.components.IUiComponentInitializer#init(java.awt.Component, com.kwz.common.IContext)
     */
    public void init(Component component, IContext ctx) throws BadContextException {
        try{
	        if(ctx.containsKey(UI_INIT_MODEL)){
	            ((JComboBox)component).setModel((ComboBoxModel)ctx.getObjectProperty(UI_INIT_MODEL));
	        }
	        
        }catch(CommonException ce){
            ExceptionManager.processExceptionNotThrow(this, ce);
        }

    }

    /* (non-Javadoc)
     * @see com.kwz.common.ui.components.IUiComponentInitializer#getDefaultInitializerContext()
     */
    public IContext getDefaultInitializerContext() {
        return getDefaultInitializerContext(getContextInitializer());
    }
    
    /* (non-Javadoc)
     * @see com.kwz.common.ui.components.IUiComponentInitializer#getDefaultInitializerContext(com.kwz.common.ui.components.IUiComponentContextInitializer)
     */
    public IContext getDefaultInitializerContext(IUiComponentContextInitializer contextInitializer) {
        IContext context = new Context();
        return context;
    }
}
